import 'package:app/services/address.dart';
import 'package:app/services/dio_manager.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

import 'leave_model.dart';

class LeaveController extends GetxController{



  TextEditingController editingController = TextEditingController();

  List dataArr = [];

  int page = 1;

  requestData({var search})async{

    var params = {
      // 'search':'Appointment',
      'search':search,
      'page':page,
      'limit':10,
    };
    var json = await DioManager().kkRequest(Address.hrLeavePage,params:params,method: 'get');
    LeaveModel model = LeaveModel.fromJson(json);
    if(page == 1){
      dataArr.clear();
      if(model.data!=null){
       dataArr.clear();
       dataArr.addAll(model.data!);
       update();
     }
    }else{

      if(model.data!=null){
        dataArr.addAll(model.data!);
      }else{
        BotToast.showText(text: '暂无更多');
      }
    }
    update();
  }


  onRefresh()async{
    page = 1;
    requestData(search: editingController.text);
  }

  onLoad()async{
    page++;
    requestData(search: editingController.text);
  }

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    requestData();
  }

}